package com.niit.order.service.impl;


import com.niit.order.entity.User;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.SendTo;


/**
 * @author yaojianfeng
 * @EnableBinding 绑定通道
 */
@EnableBinding({Processor.class, MySink.class})
public class MessageReceiver {

    @StreamListener(Sink.INPUT)
    @SendTo(Processor.OUTPUT)
    public String receiveMessage(Message<String> msg) {
        System.out.println("order-service-output received message: " + msg.getPayload());
        return msg.getPayload();
    }


    @StreamListener(MySink.INPUT1)
    public void receiveMessage1(Message<String> msg) {
        System.out.println("order-service-output1 received message: " + msg.getPayload());
    }

    @StreamListener(MySink.INPUT2)
    public void receiveMessage2(Message<String> msg) {
        System.out.println("order-service-output2 received message: " + msg.getPayload());
    }

    @StreamListener(MySink.INPUT2)
    public void receiveMessage2(User user) {
        System.out.println("order-service-output2 received message: " + user);
    }


}